(function (global, factory) {
	typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('babel-runtime/helpers/classCallCheck'), require('babel-runtime/helpers/extends'), require('babel-runtime/helpers/objectWithoutProperties'), require('babel-runtime/core-js/json/stringify'), require('babel-runtime/helpers/typeof'), require('babel-runtime/core-js/object/assign'), require('babel-runtime/helpers/createClass')) :
	typeof define === 'function' && define.amd ? define(['exports', 'babel-runtime/helpers/classCallCheck', 'babel-runtime/helpers/extends', 'babel-runtime/helpers/objectWithoutProperties', 'babel-runtime/core-js/json/stringify', 'babel-runtime/helpers/typeof', 'babel-runtime/core-js/object/assign', 'babel-runtime/helpers/createClass'], factory) :
	(factory((global.stat = {}),global._classCallCheck,global._extends,global._objectWithoutProperties,global._JSON$stringify,global._typeof,global._Object$assign,global._createClass));
}(this, (function (exports,_classCallCheck,_extends,_objectWithoutProperties,_JSON$stringify,_typeof,_Object$assign,_createClass) { 'use strict';

	_classCallCheck = _classCallCheck && _classCallCheck.hasOwnProperty('default') ? _classCallCheck['default'] : _classCallCheck;
	_extends = _extends && _extends.hasOwnProperty('default') ? _extends['default'] : _extends;
	_objectWithoutProperties = _objectWithoutProperties && _objectWithoutProperties.hasOwnProperty('default') ? _objectWithoutProperties['default'] : _objectWithoutProperties;
	_JSON$stringify = _JSON$stringify && _JSON$stringify.hasOwnProperty('default') ? _JSON$stringify['default'] : _JSON$stringify;
	_typeof = _typeof && _typeof.hasOwnProperty('default') ? _typeof['default'] : _typeof;
	_Object$assign = _Object$assign && _Object$assign.hasOwnProperty('default') ? _Object$assign['default'] : _Object$assign;
	_createClass = _createClass && _createClass.hasOwnProperty('default') ? _createClass['default'] : _createClass;

	var VuePlugin = function VuePlugin(Vue) {
		var _this = this;

		var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

		_classCallCheck(this, VuePlugin);

		this.apply = function (stat) {
			console.log('Stat use: VuePlugin');

			var addNode = function addNode(el) {
				var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
				    _ref$value = _ref.value,
				    value = _ref$value === undefined ? {} : _ref$value;

				return stat.addNode(el, value);
			};

			var removeNode = function removeNode(el) {
				var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
				    _ref2$value = _ref2.value,
				    value = _ref2$value === undefined ? {} : _ref2$value;

				return stat.removeNode(value.id);
			};

			_this.Vue.directive('stat', {
				inserted: addNode,
				componentUpdated: addNode,
				unbind: removeNode
			});
		};

		this.Vue = Vue;
		this.options = options;
	};

	var getLocation = function getLocation() {
	  return window.location;
	};

	var format = (function () {
		var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
		    _ref$channel = _ref.channel,
		    channel = _ref$channel === undefined ? '' : _ref$channel,
		    _ref$platform = _ref.platform,
		    platform = _ref$platform === undefined ? '' : _ref$platform,
		    _ref$userId = _ref.userId,
		    userId = _ref$userId === undefined ? '' : _ref$userId;

		var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];

		if (!Array.isArray(data)) data = [data];

		var records = data.map(function (item) {
			var _pageParams = _JSON$stringify(item.pageParams);
			var _parentParams = _JSON$stringify(item.parentParams);
			var _actionParams = _JSON$stringify(item.actionParams);

			return {
				triggerTime: new Date().getTime().toString(),
				userId: userId,
				page: item.page,
				pageParams: _pageParams === '{}' ? '' : _pageParams,
				parentPage: item.parentPage,
				parentParams: _parentParams === '{}' ? '' : _parentParams,
				action: item.type || item.action,
				actionParams: _actionParams === '{}' ? '' : _actionParams,
				target: item.target
			};
		});

		return {
			base: {
				channel: channel,
				platform: platform
			},
			records: records
		};
	});

	var format$1 = (function (dataList) {
		var sdkData = function sdkData(data) {
			return {
				actionType: data.actionType || data.action,
				action: data.actionType || data.action,

				pageName: data.pageName || data.page,
				page: data.pageName || data.page,

				target: data.target,
				parentPage: data.parentPage || '/',
				pageFrom: data.pageFrom || [data.page || '/'],
				actionParams: data.actionParams,
				pageParams: data.pageParams
			};
		};

		return dataList.map(function (item) {
			return sdkData(item);
		});
	});

	var ua = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' ? window.navigator.userAgent : '';

	var isIphone = function isIphone() {
	  return ua.indexOf("iPhone") > -1;
	};

	var isIpad = function isIpad() {
	  return ua.indexOf("iPad") > -1;
	};

	var isApple = function isApple() {
	  return isIphone() || isIpad();
	};

	var H5_format = function H5_format() {
		var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

		var _ref$channel = _ref.channel,
		    channel = _ref$channel === undefined ? '' : _ref$channel,
		    _ref$platform = _ref.platform,
		    platform = _ref$platform === undefined ? '' : _ref$platform,
		    _ref$userId = _ref.userId,
		    userId = _ref$userId === undefined ? '' : _ref$userId,
		    options = _objectWithoutProperties(_ref, ['channel', 'platform', 'userId']);

		_classCallCheck(this, H5_format);

		_initialiseProps.call(this);

		this.options = _extends({
			channel: channel,
			platform: platform || (isApple() ? 'ios' : 'android'),
			userId: userId
		}, options);
	};

	var _initialiseProps = function _initialiseProps() {
		var _this = this;

		this.apply = function (stat) {
			console.log('Stat use: H5_format');

			stat.setClientDetail = function (options) {
				return _Object$assign(_this.options, options);
			};

			stat.pipe(function (datas) {
				return [format(_this.options, datas)];
			});
		};
	};

	var GT = function GT(key) {
	  return window.sessionStorage.getItem(key);
	};
	var ST = function ST(key, value) {
	  return window.sessionStorage.setItem(key, value);
	};

	var _GT = function _GT(key) {
	  var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '{}';
	  return JSON.parse(GT(key) || ST(key, type) || type);
	};
	var _ST = function _ST(key, value) {
	  return ST(key, _JSON$stringify(value));
	};

	var _hostSdk = {
		stat: function stat() {},
		setStatFun: function setStatFun() {},
		init: function init() {},
		getInfo: function getInfo() {},
		versionVerify: function versionVerify() {},
		uploadPageEndStatistics: function uploadPageEndStatistics() {}
	};

	var key = 'NativePlugin-duration';
	var getTime = function getTime() {
		return _GT(key, Date.now());
	};
	var setTime = function setTime(value) {
		return _ST(key, value);
	};
	var time = getTime();
	var _time = 0;
	var diff = 0;
	var updateTime = function updateTime() {
		_time = Date.now();
		diff = _time - time;
		time = _time;

		setTime(time);

		return true;
	};

	var NativePlugin = function NativePlugin() {
		var _this = this;

		var hostSdk = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _hostSdk;

		var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

		var _ref$pathFilter = _ref.pathFilter,
		    pathFilter = _ref$pathFilter === undefined ? [] : _ref$pathFilter,
		    options = _objectWithoutProperties(_ref, ['pathFilter']);

		_classCallCheck(this, NativePlugin);

		this.apply = function (stat) {
			console.log('Stat use: NativePlugin');

			stat.pipe(format$1);

			stat.setOptions({
				report: function report(data) {
					var _hostSdk2;

					for (var _len = arguments.length, arg = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
						arg[_key - 1] = arguments[_key];
					}

					return (_hostSdk2 = _this.hostSdk).stat.apply(_hostSdk2, [_JSON$stringify(data)].concat(arg));
				}
			});

			var getDiffData = function getDiffData() {
				var isSdk = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
				var _diff = arguments[1];
				return { pageName: stat.getCurrentData()[0][isSdk ? 'pageName' : 'parentPage'], duration: _diff || diff };
			};

			_this.hostSdk.pause(function () {
				if (_this.pathFilter.find(function (item) {
					return getLocation().pathname.indexOf(item) > -1;
				})) return;

				var params = updateTime() && getDiffData(true);

				if (params.duration > 500) _this.hostSdk.uploadPageEndStatistics(params);
			});

			_this.hostSdk.setStatFun(function () {
				updateTime() && _this.hostSdk.uploadPageEndStatistics(getDiffData(true));

				return stat.getCurrentData();
			});

			if (stat.route) {
				var uploadPageEnd = function uploadPageEnd(chain) {
					return chain.length > 1 && updateTime() && _this.hostSdk.uploadPageEndStatistics(getDiffData());
				};

				uploadPageEnd(stat.route.getOwnChain());
				stat.route.afterEach(function (to) {
					return uploadPageEnd(to.chain);
				});
			}
		};

		this.hostSdk = hostSdk;
		this.pathFilter = pathFilter;
		this.options = options;
	};

	var _hostSdk$1 = {
		setStatFun: function setStatFun() {},
		partyCall: function partyCall() {}
	};

	var key$1 = 'NativePlugin-duration';
	var getTime$1 = function getTime() {
		return _GT(key$1, Date.now());
	};
	var setTime$1 = function setTime(value) {
		return _ST(key$1, value);
	};
	var time$1 = getTime$1();
	var _time$1 = 0;
	var diff$1 = 0;
	var updateTime$1 = function updateTime() {
		_time$1 = Date.now();
		diff$1 = _time$1 - time$1;
		time$1 = _time$1;

		setTime$1(time$1);

		return true;
	};

	var NativePlugin$1 = function NativePlugin() {
		var _this = this;

		var hostSdk = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _hostSdk$1;

		var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

		var _ref$pathFilter = _ref.pathFilter,
		    pathFilter = _ref$pathFilter === undefined ? [] : _ref$pathFilter,
		    options = _objectWithoutProperties(_ref, ['pathFilter']);

		_classCallCheck(this, NativePlugin);

		this.apply = function (stat) {
			console.log('Stat use: NativePlugin');

			stat.pipe(format$1);

			stat.setOptions({
				report: function report(data) {
					var _hostSdk2;

					for (var _len = arguments.length, arg = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
						arg[_key - 1] = arguments[_key];
					}

					return (_hostSdk2 = _this.hostSdk).partyCall.apply(_hostSdk2, ['stat', _JSON$stringify(data)].concat(arg));
				}
			});

			var getDiffData = function getDiffData() {
				var isSdk = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
				var _diff = arguments[1];
				return { pageName: stat.getCurrentData()[0][isSdk ? 'pageName' : 'parentPage'], duration: _diff || diff$1 };
			};

			_this.hostSdk.addPause(function () {
				if (_this.pathFilter.find(function (item) {
					return getLocation().pathname.indexOf(item) > -1;
				})) return;

				var params = updateTime$1() && getDiffData(true);

				if (params.duration > 500) _this.hostSdk.partyCall('uploadPageEndStatistics', params);
			});

			_this.hostSdk.setStatFun(function () {
				updateTime$1() && _this.hostSdk.partyCall('uploadPageEndStatistics', getDiffData(true));

				return stat.getCurrentData();
			});

			if (stat.route) {
				var uploadPageEnd = function uploadPageEnd(chain) {
					return chain.length > 1 && updateTime$1() && _this.hostSdk.partyCall('uploadPageEndStatistics', getDiffData());
				};

				uploadPageEnd(stat.route.getOwnChain());
				stat.route.afterEach(function (to) {
					return uploadPageEnd(to.chain);
				});
			}
		};

		this.hostSdk = hostSdk;
		this.pathFilter = pathFilter;
		this.options = options;
	};

	var key$2 = 'WatchRoutePlugin-pageFromMemory';
	var getMemory = function getMemory() {
		return _GT(key$2);
	};
	var _setMemory = function _setMemory(value) {
		return _ST(key$2, value);
	};

	var WatchRoutePlugin = function () {
		function WatchRoutePlugin(WatchRoute) {
			var _this = this;

			var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

			_classCallCheck(this, WatchRoutePlugin);

			this.apply = function (stat) {
				console.log('Stat use: WatchRoutePlugin');

				stat.route = _this.route;

				var reg = /^https?:\/\/[^/]+/;
				var getPageName = function getPageName() {
					var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
					return _this.pageFromMemory[path.replace(reg, '').split('?')[0]] || '/';
				};

				stat.listen('/', function (data, params) {
					var path = params.fullPath;
					if (!_this.pageFromMemory[path] && data.page) _this.setMemory(path, data.page);

					var parent = _this.route.parentPage;

					return {
						parentPage: getPageName(parent.href || ''),
						parentParams: _extends({}, parent.query)
					};
				});

				stat.pipe(function (datas) {
					var chain = _this.route.getOwnChain().reverse();
					if (!chain.length) chain.unshift(getLocation().href);

					var pageFrom = chain.map(getPageName);

					datas.forEach(function (data) {
						return !data.pageFrom && (data.pageFrom = pageFrom);
					});

					return datas;
				});
			};

			this.options = options;

			this.route = new WatchRoute(_extends({ rightAway: true }, options));

			this.pageFromMemory = getMemory();
		}

		_createClass(WatchRoutePlugin, [{
			key: 'setMemory',
			value: function setMemory(key, value) {
				this.pageFromMemory[key] = value;

				_setMemory(this.pageFromMemory);
			}
		}]);

		return WatchRoutePlugin;
	}();

	exports.VuePlugin = VuePlugin;
	exports.H5_format = H5_format;
	exports.NativePlugin = NativePlugin;
	exports.NativePlugin_3 = NativePlugin$1;
	exports.WatchRoutePlugin = WatchRoutePlugin;

	Object.defineProperty(exports, '__esModule', { value: true });

})));
